package org.bbelovic.devel.exercises.sequences.impl;

import java.util.ArrayList;
import java.util.List;

import org.bbelovic.devel.exercises.sequences.SequenceGenerator;

/**
 * Sequence of numbers starting with 1, 2, 4, 7, 11, 16, 22, 29.. Also called Lazy Caterer numbers, 
 * defined at http://oeis.org/A000124.
 */
public class LazyCatererSequenceGenerator implements SequenceGenerator {

    private int step = 0;

    public List<Integer> generateSequence(int n) {
        final List<Integer> result = new ArrayList<Integer>();
        int act = 1;
        for (int i = act; i <= n; i++) {
            act = act + step++;
            result.add(act);
        }
        return result;
    }

}
